<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="test"></div>
    <script src="../lib//react.development.js"></script>
    <script src="../lib/react-dom.development.js"></script>
    <script src="../lib/babel.min.js"></script>
    <script src="../lib/prop-types.js"></script>
    <script type="text/babel">
        class Demo extends React.Component {
            state = { status: false }
            render() {
                return (
                    <div>
                        <p>回调 ref 内联形式：更新时会执行两次，每次渲染时会创建新的函数实例，清空旧的 ref（传入 null）</p>
                        {/* <input type="text" ref={(input) => { this.input = input; console.log(input) }} placeholder="click" /> */}
                        <button onClick={this.onClick}>click</button>
                        <button onClick={this.onClick1}>setState</button>
                        <p>绑定函数可以避免</p>
                        <input type="text" ref={this.saveInput} placeholder="click" />
                    </div>
                )
            }
            onClick = () => {
                const { input } = this
                console.log(input.value)
            }
            onClick1 = () => {
                const { status } = this.state
                this.setState({ status: !status })
            }
            saveInput = (input2)=>{
                // 只会在第一次渲染调用，和内联形式没区别
                this.input2 = input2
                console.log(input2)
            }
        }
        ReactDOM.render(<Demo />, document.getElementById('test'))
    </script>
</body>

</html>